const fs = require("fs");
const { expect } = require("expect");
const mock = require("jest-mock");
const { describe, it, run, resetState } = require("jest-circus");

exports.runTest = async function (testFile) {
    const code = await fs.promises.readFile(testFile, "utf8");
    const testResult = {
        success: false,
        errMessage: null
    }

    // const expect = received => ({
    //     toBe: expected => {
    //         console.log('toBe', received, expected);
    //         if (expected !== received) {
    //             throw new Error(`Expected ${expected} but received ${received}.`);
    //         }
    //         return true
    //     }
    // })

    try {
        resetState();
        eval(code)

        const { testResults } = await run();
        testResult.success = true;
        testResult.errMessage = testResults
        // testResult.success = testResults.every((result) => !result.errors.length);
    } catch (e) {
        testResult.errMessage = e.message
    }
    return testResult
}; 